<!--
 * @Author: 菅书繎 2032642089@qq.com
 * @Date: 2025-09-11 08:40:05
 * @LastEditors: 菅书繎 2032642089@qq.com
 * @LastEditTime: 2025-09-16 11:26:28
 * @FilePath: \大三上 前端\city\src\pages\components\Right1.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div>
        <Title :title="title"></Title>
          {{ ed }}
        <!-- 提供图表容器 -->
        <div ref="right1" style="height: 150px;margin-top:10px"></div>
    </div>
</template>
<script>
import { Line } from '@antv/g2plot';
import { get } from '@/utils/request';
import moment from 'moment';
import { mapState } from 'vuex';
export default {
    data() {
        return {
            title: '实时湿度曲线',
            //存放设备状态数据
            humData: [],
            params: {
                page: 1,
                pageSize: 100
            },
            linePlot: null
        }
    },
    computed: {
        ...mapState(['ed'])
    },
    //侦听器 侦听数据
    watch: {
        ed: {
            handler(n, o) {
                //根据设备信息重新查询数据，重新渲染图表
                this.params.engineer_id = n.engineer_id;
                this.params.device_id = n.device_id;
                this.getEmpData();
                //根据最新获取的数据重新渲染图表
                this.linePlot.changeData(this.humData);
            },

            //深度监听
            deep: true
        }
    },
    methods: {
        photo() {

            this.linePlot = new Line(this.$refs.right1, {
                data: this.humData,
                xField: 'insert_time',
                yField: 'humidity',
                stepType: 'vh',
            });

            this.linePlot.render();
        },


        //封装请求获取设备数据
        async getEmpData() {
            let res = await get('/dashboard/pageQueryTodayData', this.params);
            console.log(res, '2222');

            let temp = [];
            //将后端获取的数据设置给tempData
            res.data.list.forEach((item, index, arr) => {
                //由于刻度混乱 将第一条数据设置为15.4
                arr[0].humidity = 10;
                //item表示数组每一项
                item.insert_time = moment(item.insert_time).format("HH:mm");
                //由于查询数据密度密集 需要将数据处理 每隔10条数据取一条数据
                if (index % 10 == 0) {
                    temp.push(arr[index])
                }
            });


            this.humData = temp;




        }

    },
    async mounted() {
        await this.getEmpData();
        this.photo();
    }
}


</script>
<style lang="less" scoped></style>